package com.balabala.gym_user.controller.admin;


import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_user.pojo.dto.VenuesQueryDto;
import com.balabala.gym_user.pojo.entity.Venues;
import com.balabala.gym_user.pojo.vo.VenuesQueryVo;
import com.balabala.gym_user.service.VenuesService;
import com.balabala.result.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/venues")
@Api(tags = "场馆后台接口")
@Slf4j
@CrossOrigin
public class VenuesController {

    @Autowired
    private   VenuesService venuesService;

    @GetMapping("/getVenuesById/{id}")
    @ApiOperation("根据id查询场馆所有信息")
    public Result findAllById(@PathVariable("id") Long id){
        log.info("通过查询场馆信息");
        return  Result.ok(ResultEnum.GENERALLY_SUCCESS,venuesService.getById(id));
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("根据id删除场馆信息")
    public Result deleteByVenId(@PathVariable Long id){
        log.info("删除数据");
        return  Result.ok(ResultEnum.GENERALLY_SUCCESS,venuesService.removeById(id));
    }

    @PostMapping("/getVenuesPageList")
    @ApiOperation("根据场馆名称模糊查询")
    public Result getVenuesPageList(@RequestBody VenuesQueryDto venuesQueryDto){

        PageHelper.startPage(venuesQueryDto.getPage(), venuesQueryDto.getLimit());
        List<VenuesQueryVo> venuesQueryVoList = venuesService.findName(venuesQueryDto);
        PageInfo<VenuesQueryVo> pageInfo = new PageInfo<>(venuesQueryVoList);
        return Result.ok(venuesQueryVoList, pageInfo.getTotal());
    }

    @PostMapping("/add")
    @ApiOperation("添加场馆信息")
    public  Result addVenues(@RequestBody Venues venues){
            log.info("添加场馆信息");
            return Result.ok(ResultEnum.GENERALLY_SUCCESS,venuesService.save(venues));

    }

    @PostMapping("/update")
    @ApiOperation("修改场馆信息")
    public  Result insertVenues(@RequestBody Venues venues){
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,venuesService.updateById(venues));

    }




















}
